package com.wanmait.wanmarecruit.webController;

import com.github.pagehelper.PageInfo;
import com.wanmait.wanmarecruit.entity.*;
import com.wanmait.wanmarecruit.service.impl.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("web")
public class WebPositionListController {

    @Resource
    private PositionServiceImpl positionService;

    @Resource
    private PositionTypeServiceImpl positionTypeService;

    @Resource
    private WorkExperienceTypeServiceImpl workExperienceTypeService;

    @Resource
    private EducationServiceImpl educationService;

    @Resource
    private SalaryServiceImpl salaryService;

    @Resource
    private ConfigServiceImpl configService;

    @RequestMapping("/personal/positionList")
    public ModelAndView positionList(){
        ModelAndView modelAndView = new ModelAndView();

        int positionCount = (int)positionService.count();
        modelAndView.addObject("positionCount",positionCount);

        List<PositionType> positionTypes = positionTypeService.list();
        modelAndView.addObject("positionTypes",positionTypes);

        List<WorkExperienceType> workExperienceTypes = workExperienceTypeService.getAllWorkExperienceAndPositionCount();
        modelAndView.addObject("workExperienceTypes",workExperienceTypes);

        List<Education> educations = educationService.getAllEducationAndPositionCount();
        modelAndView.addObject("educations",educations);

        List<Salary> salaries = salaryService.getAllSalaryAndPositionCount();
        modelAndView.addObject("salaries",salaries);

        return modelAndView;
    }

    @RequestMapping("/personal/positionListTable")
    @ModelAttribute("positionPageInfo")
    public PageInfo<Position> positionListTable(Position position, City city, Integer positionTypeId, Integer[] workExperienceTypeIds, Integer[] educationIds, Integer[] salaryIds, Integer about, Integer pageNum){
        if(pageNum==null){
            pageNum=1;
        }
        int pageSize = Integer.parseInt(configService.getByKeyword("position_list_paging_size").getConfigValue());
        return positionService.getPositionByThings(position,city,positionTypeId,workExperienceTypeIds,educationIds,salaryIds,about,pageNum,pageSize);
    }

}
